﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="Brushes.xaml" ></ResourceDictionary>
    </ResourceDictionary.MergedDictionaries>

    <Color x:Key="ControlPressedColor">#FF211AA9</Color>
    <Color x:Key="DisabledBorderLightColor">#FFAAAAAA</Color>
    <Color x:Key="DisabledControlDarkColor">#FFC5CBF9</Color>


    <ControlTemplate x:Key="ExpanderToggleButton"
                 TargetType="{x:Type ToggleButton}" >        
        <Border
          CornerRadius="0"
          BorderThickness="0" >
            <Border.Background>
                <SolidColorBrush Color="Transparent"></SolidColorBrush>
            </Border.Background>
            <VisualStateManager.VisualStateGroups>
                <VisualStateGroup x:Name="CommonStates">
                    <VisualState x:Name="Normal" />
                    <VisualState x:Name="MouseOver">
                        <Storyboard>
                            <ColorAnimationUsingKeyFrames Storyboard.TargetName="Border" 
                                                          Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)">
                                <EasingColorKeyFrame KeyTime="0" Value="{DynamicResource MetroBlue}" />
                            </ColorAnimationUsingKeyFrames>
                            <ColorAnimationUsingKeyFrames Storyboard.TargetName="Border" 
                                                          Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)">
                                <EasingColorKeyFrame KeyTime="0" Value="{DynamicResource MetroBlue}" />
                            </ColorAnimationUsingKeyFrames>

                        </Storyboard>
                    </VisualState>
                    <VisualState x:Name="Pressed">
                        <Storyboard>
                            <ColorAnimationUsingKeyFrames Storyboard.TargetName="Border"
                                          Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)">
                                <EasingColorKeyFrame KeyTime="0" Value="{StaticResource ControlPressedColor}" />
                            </ColorAnimationUsingKeyFrames>
                        </Storyboard>
                    </VisualState>
                    <VisualState x:Name="Disabled">
                        <Storyboard>
                            <ColorAnimationUsingKeyFrames Storyboard.TargetName="Border"
                                          Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)">
                                <EasingColorKeyFrame KeyTime="0"
                                   Value="{StaticResource DisabledControlDarkColor}" />
                            </ColorAnimationUsingKeyFrames>
                            <ColorAnimationUsingKeyFrames Storyboard.TargetName="Border"
                                          Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)">
                                <EasingColorKeyFrame KeyTime="0"
                                   Value="{StaticResource DisabledBorderLightColor}" />
                            </ColorAnimationUsingKeyFrames>
                        </Storyboard>
                    </VisualState>
                </VisualStateGroup>
                <VisualStateGroup x:Name="CheckStates">
                    <VisualState x:Name="Checked">
                    </VisualState>
                    <VisualState x:Name="Unchecked" />
                    <VisualState x:Name="Indeterminate" />
                </VisualStateGroup>
            </VisualStateManager.VisualStateGroups>
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="8"></ColumnDefinition>
                    <ColumnDefinition Width="*"></ColumnDefinition>
                </Grid.ColumnDefinitions>
                <Border Grid.Column="0" Width="10" x:Name="Border" Height="Auto" >
                    <Border.Background>
                        <SolidColorBrush Color="Gray"></SolidColorBrush>
                    </Border.Background>
                </Border>
                <ContentPresenter Grid.Column="1" >
                </ContentPresenter>
            </Grid>
        </Border>
    </ControlTemplate>


    <ControlTemplate x:Key="ExpanderToggleButtonRTL"
                 TargetType="{x:Type ToggleButton}" >
        <Border
          CornerRadius="0"
          BorderThickness="0" >
            <Border.Background>
                <SolidColorBrush Color="Transparent"></SolidColorBrush>
            </Border.Background>
            <VisualStateManager.VisualStateGroups>
                <VisualStateGroup x:Name="CommonStates">
                    <VisualState x:Name="Normal" />
                    <VisualState x:Name="MouseOver">
                        <Storyboard>
                            <ColorAnimationUsingKeyFrames Storyboard.TargetName="Border" 
                                                          Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)">
                                <EasingColorKeyFrame KeyTime="0" Value="{DynamicResource MetroBlue}" />
                            </ColorAnimationUsingKeyFrames>
                            <ColorAnimationUsingKeyFrames Storyboard.TargetName="Border" 
                                                          Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)">
                                <EasingColorKeyFrame KeyTime="0" Value="{DynamicResource MetroBlue}" />
                            </ColorAnimationUsingKeyFrames>

                        </Storyboard>
                    </VisualState>
                    <VisualState x:Name="Pressed">
                        <Storyboard>
                            <ColorAnimationUsingKeyFrames Storyboard.TargetName="Border"
                                          Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)">
                                <EasingColorKeyFrame KeyTime="0" Value="{StaticResource ControlPressedColor}" />
                            </ColorAnimationUsingKeyFrames>
                        </Storyboard>
                    </VisualState>
                    <VisualState x:Name="Disabled">
                        <Storyboard>
                            <ColorAnimationUsingKeyFrames Storyboard.TargetName="Border"
                                          Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)">
                                <EasingColorKeyFrame KeyTime="0"
                                   Value="{StaticResource DisabledControlDarkColor}" />
                            </ColorAnimationUsingKeyFrames>
                            <ColorAnimationUsingKeyFrames Storyboard.TargetName="Border"
                                          Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)">
                                <EasingColorKeyFrame KeyTime="0"
                                   Value="{StaticResource DisabledBorderLightColor}" />
                            </ColorAnimationUsingKeyFrames>
                        </Storyboard>
                    </VisualState>
                </VisualStateGroup>
                <VisualStateGroup x:Name="CheckStates">
                    <VisualState x:Name="Checked">
                    </VisualState>
                    <VisualState x:Name="Unchecked" />
                    <VisualState x:Name="Indeterminate" />
                </VisualStateGroup>
            </VisualStateManager.VisualStateGroups>
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"></ColumnDefinition>
                    <ColumnDefinition Width="8"></ColumnDefinition>
                </Grid.ColumnDefinitions>
                <Border Grid.Column="1" Width="10" x:Name="Border" Height="Auto" >
                    <Border.Background>
                        <SolidColorBrush Color="Gray"></SolidColorBrush>
                    </Border.Background>
                </Border>
                <ContentPresenter Grid.Column="0" >
                </ContentPresenter>
            </Grid>
        </Border>
    </ControlTemplate>

    <Style TargetType="{x:Type Expander}" x:Key="MetroExpander">
        <Style.Triggers>
            <Trigger Property="ExpandDirection" Value="Left">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type Expander}">
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition x:Name="ContentRow" Width="0" />
                                    <ColumnDefinition Width="Auto" />                                    
                                </Grid.ColumnDefinitions>
                                <VisualStateManager.VisualStateGroups>
                                    <VisualStateGroup x:Name="CommonStates">
                                        <VisualState x:Name="Normal" />
                                        <VisualState x:Name="MouseOver" />
                                        <VisualState x:Name="Disabled">
                                            <Storyboard>
                                                <ColorAnimationUsingKeyFrames Storyboard.TargetName="Border" Storyboard.TargetProperty="(Panel.Background).(GradientBrush.GradientStops)[1].(GradientStop.Color)">
                                                    <EasingColorKeyFrame KeyTime="0" Value="{StaticResource DisabledControlDarkColor}" />
                                                </ColorAnimationUsingKeyFrames>
                                                <ColorAnimationUsingKeyFrames Storyboard.TargetName="Border"
                                                Storyboard.TargetProperty="(Border.BorderBrush).(GradientBrush.GradientStops)[1].(GradientStop.Color)">
                                                    <EasingColorKeyFrame KeyTime="0" Value="{StaticResource DisabledBorderLightColor}" />
                                                </ColorAnimationUsingKeyFrames>
                                            </Storyboard>
                                        </VisualState>
                                    </VisualStateGroup>
                                </VisualStateManager.VisualStateGroups>
                                <Border x:Name="Content"
                                      Grid.Column="0"
                                      BorderThickness="0"
                                      CornerRadius="0">
                                    <Border.BorderBrush>
                                        <SolidColorBrush Color="LightGray" />
                                    </Border.BorderBrush>
                                    <ContentPresenter Margin="0" />
                                </Border>
                                <Border x:Name="Border"
                                        Grid.Column="1"
                                        BorderThickness="0"
                                        CornerRadius="0">
                                    <Border.BorderBrush>
                                        <LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
                                            <GradientStop Color="{DynamicResource BorderLightColor}" Offset="0" />
                                            <GradientStop Color="{DynamicResource BorderDarkColor}" Offset="1" />
                                        </LinearGradientBrush>
                                    </Border.BorderBrush>
                                    <Grid>
                                        <ToggleButton OverridesDefaultStyle="True" 
                                                      Template="{StaticResource ExpanderToggleButtonRTL}" 
                                                      IsChecked="{Binding IsExpanded, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" 
                                                      >
                                            <ToggleButton.Style>
                                                <Style TargetType="ToggleButton">
                                                    <Style.Triggers>
                                                        <Trigger Property="IsMouseOver" Value="True">
                                                            <Setter Property="Foreground" Value="{DynamicResource MetroBlueColorBrush}"></Setter>
                                                        </Trigger>
                                                    </Style.Triggers>
                                                </Style>
                                            </ToggleButton.Style>
                                            <Grid Margin="5">
                                                <Grid.LayoutTransform>
                                                    <TransformGroup>
                                                        <RotateTransform CenterX="5" CenterY="5" Angle="90" />
                                                    </TransformGroup>
                                                </Grid.LayoutTransform>
                                                <ContentPresenter  Margin="0" 
                                                                   ContentSource="Header" 
                                                                   RecognizesAccessKey="True" >
                                                </ContentPresenter>
                                            </Grid>
                                        </ToggleButton>
                                    </Grid>
                                </Border>                              
                            </Grid>
                            <ControlTemplate.Triggers>
                                <Trigger Property="IsExpanded" Value="True">
                                    <Setter TargetName="ContentRow" Property="Width" Value="{Binding DesiredWidth, ElementName=Content}" />
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Trigger>

            <Trigger Property="ExpandDirection" Value="Right">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type Expander}">
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto" />
                                    <ColumnDefinition x:Name="ContentRow" Width="0" />
                                </Grid.ColumnDefinitions>
                                <VisualStateManager.VisualStateGroups>
                                    <VisualStateGroup x:Name="CommonStates">
                                        <VisualState x:Name="Normal" />
                                        <VisualState x:Name="MouseOver" />
                                        <VisualState x:Name="Disabled">
                                            <Storyboard>
                                                <ColorAnimationUsingKeyFrames Storyboard.TargetName="Border" Storyboard.TargetProperty="(Panel.Background).(GradientBrush.GradientStops)[1].(GradientStop.Color)">
                                                    <EasingColorKeyFrame KeyTime="0" Value="{StaticResource DisabledControlDarkColor}" />
                                                </ColorAnimationUsingKeyFrames>
                                                <ColorAnimationUsingKeyFrames Storyboard.TargetName="Border"
                                                Storyboard.TargetProperty="(Border.BorderBrush).(GradientBrush.GradientStops)[1].(GradientStop.Color)">
                                                    <EasingColorKeyFrame KeyTime="0" Value="{StaticResource DisabledBorderLightColor}" />
                                                </ColorAnimationUsingKeyFrames>
                                            </Storyboard>
                                        </VisualState>
                                    </VisualStateGroup>
                                </VisualStateManager.VisualStateGroups>
                                <Border x:Name="Border"
                                        Grid.Column="0"
                                        BorderThickness="0"
                                        CornerRadius="0">
                                    <Border.BorderBrush>
                                        <LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
                                            <GradientStop Color="{DynamicResource BorderLightColor}" Offset="0" />
                                            <GradientStop Color="{DynamicResource BorderDarkColor}" Offset="1" />
                                        </LinearGradientBrush>
                                    </Border.BorderBrush>

                                    <Grid>
                                        <ToggleButton OverridesDefaultStyle="True" 
                                                      Template="{StaticResource ExpanderToggleButton}" 
                                                      IsChecked="{Binding IsExpanded, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" 
                                                      >
                                            <ToggleButton.Style>
                                                <Style TargetType="ToggleButton">
                                                    <Style.Triggers>
                                                        <Trigger Property="IsMouseOver" Value="True">
                                                            <Setter Property="Foreground" Value="{DynamicResource MetroBlueColorBrush}"></Setter>
                                                        </Trigger>
                                                    </Style.Triggers>
                                                </Style>
                                            </ToggleButton.Style>
                                            <Grid Margin="5">
                                                <Grid.LayoutTransform>
                                                    <TransformGroup>
                                                        <RotateTransform CenterX="5" CenterY="5" Angle="90" />
                                                    </TransformGroup>
                                                </Grid.LayoutTransform>
                                                <ContentPresenter  Margin="0" 
                                                                   ContentSource="Header" 
                                                                   RecognizesAccessKey="True" >
                                                </ContentPresenter>
                                            </Grid>
                                        </ToggleButton>
                                    </Grid>
                                </Border>
                                <Border x:Name="Content"
                                      Grid.Column="1"
                                      BorderThickness="0,1,1,1"
                                      CornerRadius="0">
                                    <Border.BorderBrush>
                                        <SolidColorBrush Color="LightGray" />
                                    </Border.BorderBrush>
                                    <ContentPresenter Margin="0" />
                                </Border>
                            </Grid>
                            <ControlTemplate.Triggers>
                                <Trigger Property="IsExpanded" Value="True">
                                    <Setter TargetName="ContentRow" Property="Width" Value="{Binding DesiredWidth, ElementName=Content}" />
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Trigger>
        </Style.Triggers>
    </Style>

</ResourceDictionary>